package com.bluefish.bltuan.action.admin;

import java.util.List;

import static com.bluefish.bltuan.tools.ActionUtil.copyProperties;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.apache.struts2.rest.DefaultHttpHeaders;
import org.apache.struts2.rest.HttpHeaders;

import com.bluefish.bltuan.action.AbstractAction;
import com.bluefish.bltuan.module.user.Businesser;
import com.bluefish.bltuan.service.BusinesserService;

/**
 * @author blue
 * 商家管理Action
 *
 */
@Results({
		@Result(name = "success", type = "dispatcher", location = "/page/admin/success.jsp")
 })
public class BusinesserAction extends AbstractAction {

	private static final long serialVersionUID = -371566045138381419L;
	
	private Businesser businesser;
	
	private BusinesserService businesserService;
	
	private List<Businesser> businessers;
	
	public List<Businesser> getBusinessers() {
		return businessers;
	}

	public void setBusinessers(List<Businesser> businessers) {
		this.businessers = businessers;
	}

	public void setBusinesserService(BusinesserService businesserService) {
		this.businesserService = businesserService;
	}

	public Businesser getBusinesser() {
		return businesser;
	}

	public void setBusinesser(Businesser businesser) {
		this.businesser = businesser;
	}


	@Override
	public HttpHeaders index() {
		this.businessers = this.businesserService.getAll(getPageIndex());
		return new DefaultHttpHeaders(INDEX).disableCaching();
	}

	@Override
	public HttpHeaders show() {
		this.businesser = this.businesserService.findById(this.getIntegerId());
		return new DefaultHttpHeaders(SHOW).disableCaching();
	}

	@Override
	public HttpHeaders create() {
		this.businesserService.save(this.businesser);
		return new DefaultHttpHeaders(SUCCESS).disableCaching();
	}

	@Override
	public HttpHeaders editNew() {
		return new DefaultHttpHeaders(NEW).disableCaching();
	}

	@Override
	public String update() {
		Businesser businesser = this.businesserService.findById(getIntegerId());
		copyProperties(this.businesser, businesser);
		this.businesserService.update(businesser);
		return SUCCESS;
	}

	@Override
	public String edit() {
		this.businesser = this.businesserService.findById(this.getIntegerId());
		return EDIT;
	}

	public String delete() {
		Businesser businesser = this.businesserService.findById(getIntegerId());
		this.businesserService.delete(businesser);
		return SUCCESS;
	}
	
	@Override
	public String destroy() {
		// TODO Auto-generated method stub
		return null;
	}

 
}